package com.nwork.qingmanhua.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.nwork.qingmanhua.MainActivity;
import com.nwork.qingmanhua.R;
import com.nwork.qingmanhua.adapter.RecyclerAdapter;

/**
 * Activity的第一个Fragment
 */
public class MainFragment extends Fragment {

    private RecyclerView topRecyclerView;
    private ImageView titleImage;
    private int topLayoutHeight;
    private View view;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_main, container, false);
        //设置顶部的透明区域
        init();
        FragmentActivity fragmentActivity = getActivity();
        if (fragmentActivity instanceof MainActivity) {
            MainActivity mainActivity = (MainActivity) fragmentActivity;
            topLayoutHeight = mainActivity.getTopLayoutHeight();
        }
        ViewGroup.LayoutParams layoutParams = titleImage.getLayoutParams();
        layoutParams.height = topLayoutHeight;
        titleImage.setLayoutParams(layoutParams);
        //设置RecyclerView

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        topRecyclerView.setLayoutManager(linearLayoutManager);
        topRecyclerView.setAdapter(new RecyclerAdapter(getActivity()));
        return view;
    }

    private void init() {
        titleImage = (ImageView) view.findViewById(R.id.title_img);
        topRecyclerView = (RecyclerView) view.findViewById(R.id.top_recycler_view);
    }


}
